package top.lshaci.learning.activiti.day2;

import cn.hutool.core.lang.Dict;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

import static top.lshaci.learning.activiti.util.ProcessEngineSingleton.singleton;

/**
 * PersonalTaskTest
 * <p>用户私有任务测试</p>
 * <pre>
 * </pre>
 *
 * @author lshaci
 * @since 1.0.0
 */
public class PersonalTaskTest {

    @Test
    public void test() {
        // 1.部署流程
        Deployment deployment = singleton.deploy("PersonalTask");
        System.err.println(deployment);
        // 2.启动流程
        ProcessInstance processInstance = singleton.start("PersonalTask");
        String processInstanceId = processInstance.getId();
        System.err.println("processInstanceId: " + processInstanceId);
        // 3.验证流程的状态（位置）
        // 获取当前流程 "助理买咖啡" 节点对应的Task对象
        Task t1 = singleton.taskService()
                .createTaskQuery()
                .processInstanceId(processInstanceId)
                .taskAssignee("小丽")
                .singleResult();
        System.err.println("t1: " + t1);
        Assert.assertNotNull(t1);

        System.err.println("description: " + t1.getDescription());
        List<String> outGoingTransNames = singleton.getOutGoingTransNames(t1.getId());
        System.err.println("outGoingTransNames: " + outGoingTransNames);

        singleton.taskService().complete(t1.getId(), Dict.create().set("味道", "多糖"));
        // 验证流程结束
        ProcessInstance dbProcessInstance = singleton.runtimeService()
                .createProcessInstanceQuery()
                .processInstanceId(processInstanceId)
                .singleResult();
        Assert.assertNull(dbProcessInstance);
    }
}
